<template>
  <el-form ref="form" :rules="rules" style="padding-top: 10px;" :model="form" label-width="80px">
    <el-row>
      <el-col :span="12">
        <el-form-item label="姓名" prop="name">
          <el-input v-model="form.name" />
        </el-form-item>
      </el-col>
      <el-col :span="12">
        <el-form-item label="账号" prop="account">
          <el-input v-model="form.account" />
        </el-form-item>
      </el-col>
    </el-row>
    <el-row>
      <el-col :span="12">
        <el-form-item label="工号" prop="number">
          <el-input v-model="form.number" />
        </el-form-item>
      </el-col>
      <el-col :span="12">
        <el-form-item label="性别" prop="sex">
          <el-radio-group v-model="form.sex">
            <el-radio v-for="item in sexTypes" :key="item.name" :label="item.value">
              {{ item.name }}
            </el-radio></el-radio-group>
        </el-form-item>
      </el-col>
    </el-row>
    <el-row>
      <el-col :span="12">
        <el-form-item label="血型" prop="blood">
          <el-select v-model="form.blood" style="width: 100%;" placeholder="请选择血型">
            <el-option v-for="item in bloodTypes" :key="item.name" :label="item.name" :value="item.value" />
          </el-select>
        </el-form-item>
      </el-col>
      <el-col :span="12">
        <el-form-item label="出生日期" prop="birth">
          <el-date-picker v-model="form.birth" type="date" placeholder="选择日期" style="width: 100%;" />
        </el-form-item>
      </el-col>
    </el-row>
    <el-row>
      <el-col :span="12">
        <el-form-item label="办公电话" prop="officePhone">
          <el-input v-model="form.officePhone" />
        </el-form-item>
      </el-col>
      <el-col :span="12">
        <el-form-item label="手机" prop="personalPhone">
          <el-input v-model="form.personalPhone" />
        </el-form-item>
      </el-col>
    </el-row>
    <el-row>
      <el-col :span="12">
        <el-form-item label="电子邮箱" prop="email">
          <el-input v-model="form.email" />
        </el-form-item>
      </el-col>
      <el-col :span="12">
        <el-form-item label="QQ" prop="qq">
          <el-input v-model="form.qq" />
        </el-form-item>
      </el-col>
    </el-row>
    <el-row>
      <el-col :span="12">
        <el-form-item label="启用" prop="enable">
          <el-checkbox v-model="form.enable" />
        </el-form-item>
      </el-col>
      <el-col :span="12">
        <el-form-item label="是否离职" prop="offline">
          <el-checkbox v-model="form.offline" />
        </el-form-item>
      </el-col>
    </el-row>
    <el-row>
      <el-col :span="12">
        <el-form-item label="邮政编码" prop="postCode">
          <el-input v-model="form.postCode" />
        </el-form-item>
      </el-col>
      <el-col :span="12">
        <el-form-item label="序号" prop="sequence">
          <el-input v-model="form.sequence" />
        </el-form-item>
      </el-col>
    </el-row>
    <el-form-item label="传真" prop="fax">
      <el-input v-model="form.fax" />
    </el-form-item>
    <el-form-item label="地址" prop="address">
      <el-input v-model="form.address" />
    </el-form-item>
    <!-- <el-form-item label="机构职责">
      <el-input v-model="form.description" type="textarea" />
    </el-form-item> -->
    <el-form-item label="备注" prop="remark">
      <el-input v-model="form.remark" type="textarea" />
    </el-form-item>
  </el-form>
</template>

<script>
import { sexTypes, bloodTypes } from '@/utils/dicData'
export default {
  name: 'AddUser',
  props: {
    data: {
      type: Object,
      default() {
        return {}
      }
    },
    type: {
      type: String,
      default: 'add'
    }
  },
  data() {
    return {
      sexTypes,
      bloodTypes,
      form: {
        sequence: '',
        name: '',
        account: '',
        number: '',
        sex: '',
        blood: '',
        birth: '',
        fax: '',
        officePhone: '',
        personalPhone: '',
        email: '',
        postCode: '',
        qq: '',
        enable: true,
        offline: false,
        address: '',
        description: '',
        remark: ''
      },
      rules: {
        name: [
          { required: true, message: '请输入姓名', trigger: 'change' }
        ],
        account: [
          { required: true, message: '请输入账号', trigger: 'change' }
        ],
        sex: [
          { required: true, message: '请选择性别', trigger: 'change' }
        ]
      }
    }
  },
  watch: {
    data: {
      handler(newData, oldData) {
        Object.keys(this.form).forEach(key => {
          const val = key === 'sex' ? Number(newData[key]) : newData[key]
          this.form[key] = val
        })
      },
      deep: true,
      immediate: true
    }
  },
  mounted() {
  },
  methods: {
    validateForm(fn) {
      this.$refs.form.validate((valid) => {
        fn(valid)
      })
    },
    resetForm() {
      this.$refs.form.resetFields()
    }

  }
}
</script>

<style lang="scss" scoped>

</style>
